package leetcode.Y2024M5D23;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

public class S452 {
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points,Comparator.comparingInt(x->x[1]));
        int arrows=1;
        int target=points[0][1];
        for (int i = 1; i < points.length; i++) {
            if (points[i][0]>target){
                target=points[i][1];
                arrows++;
            }

        }
        return arrows;
    }

    @Test
    public void test() {
        int[][] points = {{10, 16}, {2, 8}, {1, 6}, {7, 12}};
        System.out.println(findMinArrowShots(points));
    }

    @Test
    public void test1() {
        int[][] points = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
        System.out.println(findMinArrowShots(points));
    }

    @Test
    public void test2() {
        int[][] points = {{1, 2}, {2, 3}, {3, 4}, {4, 5}};
        System.out.println(findMinArrowShots(points));
    }
}
